import java.util.Iterator;
import java.util.List;

/**
 * @projectName: com.xiayuanxing.designPattern
 * @className: OutPutImpl
 * @author: xiayuanxing
 * @description: TODO
 * @date: 2022/1/7 11:46
 * @version: 1.0
 */
public class OutPutImpl {

    //学院集合
    List<College> collegeList;


    /**构造器*/
    public OutPutImpl(List<College> collegeList) {
        this.collegeList = collegeList;
    }

    /**遍历所有学院,然后调用printDepartment输出各个学院的系*/
    public void printCollege(){
        //从collegeList取出所有学院,Java中的List已经实现Iterator
        Iterator<College> iterator = collegeList.iterator();

        while (iterator.hasNext()){
            //取出一个学院
            College college = iterator.next();
            System.out.println("========"+college.getName()+"========");
            //得到对应迭代器
            printDepartment(college.createIterator());
        }
    }


    /**输出学院 输出系*/
    public void printDepartment(Iterator iterator){
        while (iterator.hasNext()){
            Department department = (Department)iterator.next();
            System.out.println(department.getName());
        }

    }


}
